#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char a[10001],b[10001];
int m[1000][1000];
int a_num,b_num;
int res=-1,mark;
void findL(){
    for(int i=0;i<a_num;i++){
        for(int j=0;j<b_num;j++){
           if(a[i]==b[j]){
                if(i==0||j==0)
                m[i][j]=1;
               else
                m[i][j] = m[i-1][j-1]+1;
           }
           else
            m[i][j]=0;

        }
    }
    for(int i=a_num-1;i>=0;i--){
        for(int j=0;j<b_num;j++){
          if(res<=m[i][j]){
            res=m[i][j];
            mark=i;
          }
        }
    }
}
int main()
{
    cin >> a >> b;
    a_num=strlen(a);b_num=strlen(b);
    findL();
    cout << res<< endl;
    for(int i=mark-res+1;i<mark+1;i++){
       cout << a[i];
    }
    return 0;
}

